package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import java.util.List;

import cn.acewill.yxd.yunxundian.R;

/**
 * Created by XXX on 2017/8/28.
 */

public class mulityItemAdapter extends BaseAdapter {

    private List<String> list;
    private Context context;
    private int clickTemp=-10;

    public  mulityItemAdapter(Context context,List<String> list){
         this.context=context;
        this.list=list;
     }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void setSecletion(int position) {
        clickTemp = position;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.mulity_item_view,null);
            holder=new ViewHolder();
            holder.X_checkbox= (CheckBox) convertView.findViewById(R.id.X_checkbox);
            holder.X_item_text= (TextView) convertView.findViewById(R.id.X_item_text);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.X_item_text.setText(list.get(position));
        if (clickTemp == position){
            if (holder.X_checkbox.isChecked()){
                holder.X_checkbox.setChecked(false);
            }else{
                holder.X_checkbox.setChecked(true);
            }
        }
        return convertView;
    }
   public class ViewHolder{
        TextView X_item_text;
        CheckBox X_checkbox;
    }

}
